/*
Copyright (c) 2006 - 2008  Universitaet Osnabrueck, virtUOS
Authors: Markus Ketterl, Johannes Emden, Nils Schuhmacher, Andreas Rickling

This file is part of virtPresenter.

virtPresenter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

virtPresenter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with virtPresenter.  If not, see <http://www.gnu.org/licenses/>.
*/

package virtPresenter.model
{	
	import mx.controls.treeClasses.*;
	import mx.collections.*;
	import mx.controls.Label;
	import mx.core.UITextField;

	public class virtTreeItemRenderer extends TreeItemRenderer
	{	
	    /**
	     *  Defines the constructor.
	     */      
	    public function virtTreeItemRenderer() {
	        super();
	    }
	    
	    /** 
	     * Override the set method for the data property to set the font color and style of each node.     
	     */   
	    override public function set data(value:Object):void {
	        super.data = value;
	        if(TreeListData(super.listData).hasChildren)
	        {
	            setStyle("color", 0x000000);
	            setStyle("fontWeight", 'bold');
	        }
	        else
	        {
	            setStyle("color", 0x000000);
	            setStyle("fontWeight", 'normal');
	        }  
	    }
	 
	    /** 
	     * Override the updateDisplayList() method to set the text for each tree node.
	     */      
	    override protected function updateDisplayList(unscaledWidth:Number, 
	        unscaledHeight:Number):void {
	   
	        super.updateDisplayList(unscaledWidth, unscaledHeight);
	        if(super.data)
	        {
	            if(TreeListData(super.listData).hasChildren)
	            {
	                var tmp:XMLList = 
	                    new XMLList(TreeListData(super.listData).item);
	                var myStr:int = tmp[0].children().length();
	                super.label.text =  TreeListData(super.listData).label + 
	                    " (" + myStr + " Treffer)";
	            }
	        }
	    }
	}
}